﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Codejam2014.R1B
{
    class Program
    {
        class Sample
        {
            public double c;
            public double f;
            public double x;
        }

        static void Main(string[] args)
        {
            string sampleName = "sample";
            string sampleDir = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)))+"\\";
            string iFilePath = sampleDir + sampleName + ".i.txt";
            string oFilePath = sampleDir + sampleName + ".o.txt";
            string cFilePath = sampleDir + sampleName + ".c.txt";

            string[] iLines = File.ReadAllLines(iFilePath);
            List<string> oLines = new List<string>();

            int lineCnt = 0;
            int sampleCnt = int.Parse(iLines[lineCnt++]);

            List<Sample> sampleList = new List<Sample>();
            for ( int sampleIdx = 0 ; sampleIdx < sampleCnt ; sampleIdx++ ) {
	
                string[] itemList = iLines[lineCnt++].Split(new char[] {' '});

                Sample s = new Sample();
                s.c = double.Parse(itemList[0]);
                s.f = double.Parse(itemList[1]);
                s.x = double.Parse(itemList[2]);
                sampleList.Add(s);
            }

            for (int sampleIdx = 0; sampleIdx < sampleCnt; sampleIdx++)
            {
                Sample s = sampleList[sampleIdx];
                double f_time = 0, r_time = 0, total_time = 0, x = 0, y =0;
                
                for ( int j = 0 ; ; j++ ) {
                    if (j != 0) f_time += s.c / ((j - 1) * s.f + 2);
		
	                r_time = s.x / (j*s.f+2);
	                total_time = f_time + r_time;
		
	                x = s.c / (j*s.f+2);
	                y = s.x / ((j+1)*s.f+2);
		
	                if ( x + y  > r_time ) break;
                }
                oLines.Add(string.Format("Case #{0}: {1:0.0000000}", sampleIdx + 1, total_time));
            }
            File.WriteAllLines(oFilePath, oLines);

            if (File.Exists(cFilePath))
            {
                string[] cLines = File.ReadAllLines(cFilePath);
                for (int sampleIdx = 0; sampleIdx < sampleCnt; sampleIdx++)
                {
                    string oLine = oLines[sampleIdx];
                    string cLine = cLines[sampleIdx];

                    if (oLine != cLine)
                    {
                        throw new Exception("not match");
                    }
                }
            }
       }
    }
}
